package nio;

import java.nio.CharBuffer;

public class BufferTest {
    public static void main(String[] args) {
        // ????Buffer
        CharBuffer buff = CharBuffer.allocate(8);    // ??
        System.out.println("capacity: " + buff.capacity());
        System.out.println("limit: " + buff.limit());
        System.out.println("position: " + buff.position());
        // ???????
        buff.put('a');
        buff.put('b');
        buff.put('c');      // ??
        System.out.println("????????????position = " + buff.position());
        // ????flip()????
        buff.flip();      // ??
        System.out.println("???flip()??limit = " + buff.limit());
        System.out.println("position = " + buff.position());

        // ???????????
        System.out.println("????????(position=0)??" + buff.get());  // ??
        System.out.println("??????????position = " + buff.position());

        // ????clear????
        buff.clear();     // ??
        System.out.println("???clear()??limit = " + buff.limit());
        System.out.println("???clear()??position = " + buff.position());
        System.out.println("???clear()??????????????б??????" + "????????????" + buff.get(2));    // ??
        System.out.println("??о???????position = "
                + buff.position());
    }
}
